<template>
  <view class="content">
    <view class="accept-box">
      <image class="inv-top" src="@/static/img/inv-top2.png" mode="widthFix"></image>
      <view class="item-phone">您的好友{{ mobile }}为您推荐法力</view>
      <image class="inv-bot" src="@/static/img/inv-bot.png" mode="aspectFit"></image>
      <view class="coupon-new"><image src="@/static/img/coupon-share.png" mode="widthFix"></image></view>
      <view class="inv-bot-ipt-box">
        <input type="number" v-model="acceptMobile" maxlength="11" placeholder="请输入您的手机号码" placeholder-style="font-size:24rpx" />
        <view class="item-txt" @click="changeShow()">我要领券</view>
      </view>
    </view>
    <div
        class="iframe-container"
        id="iframe-container"
        :style="`height: ${iframeHeight};`"
    >
      <!-- @load="calAutoHeight"-->
      <iframe
          src="https://d-fali.bigchun.com/web/tui.html"
          ref="iframe"
          scrolling="auto"
          frameborder="0"
          id="outerPage"
          :style="{ 'min-width': '100%', 'min-height': '100%' }"
      ></iframe>

    </div>

    <view class="ad-box">
      <!--      height:topheight*5+'px!important'-->
      <!--      <web-view  v-if="topheight" class="top_200" :class="small?'anzhuoheight':''" :style="{top:topheight+'px!important',}" src="https://d-fali.bigchun.com/web/tui.html"></web-view>-->
    </view>
    <!-- 全局通用组件 -->
    <law-common ref="lawCommon"></law-common>
  </view>
</template>

<script>
import $ from 'jquery';
export default {
  data() {
    return {
      order_id: '',
      mobile: '',
      acceptMobile: '',
      topheight:'',
      small:false,
      iframeHeight: ""
    };
  },
  onLoad(options) {
    let routes = getCurrentPages();
    let curParam = routes[routes.length - 1].options;
    this.order_id = curParam.order_id;
    this.getInvite();
    $('.content').height()
    // $('iframe>body').height()
  },
  created(){
    // 安卓
    window.isRightsOk = this.isRightsOk;
    const nav = navigator.userAgent;
    if (nav.indexOf("Android") > -1 || nav.indexOf("Adr") > -1) {
      this.small = true;
    } else if (!!nav.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
      this.small = false;
    }
    // setTimeout(()=>{
    //     this.topheight = $('.content').height();
    // },600)
    //
    setTimeout(()=>{
      var iframe = document.getElementsByTagName('iframe')
      // if(iframe.attachEvent){
      //   iframe.attachEvent("onload", function(){
      //     iframe.height =  iframe.contentWindow.document.documentElement.scrollHeight;
      //   });
      //   console.log(  $("iframe").contents().find("body").height(),"===========height()222")
      //
      //   return;
      // }else{
      //   iframe.onload = function(){
      //     // iframe.height = iframe.contentDocument.body.scrollHeight;
      //     iframe.height =  iframe.contentWindow.document.documentElement.scrollHeight;
      //   };
      //   console.log("=iframe.contentWindow.document.documentElement0:",$("iframe").contents().height())
      //   console.log(  iframe.height,"===========height()3333")
      //
      //   return;
      // }
      // this.topheight = $('.content').height();
      console.log( $("iframe").contents().find("body"),iframe,$("iframe").contents().find("body").height(),"===========height()1111",$('.content').height())
    },1200)
  },
  methods: {
    getInvite() {
      let formData = {
        id: this.order_id,
        type: 2
      };
      this.$api('index.my_inviteCode', formData).then(res => {
        this.mobile = res.data.mobile;
      });
    },
    changeShow() {
      if (!/(^1[0-9]{10}$)/.test(this.acceptMobile)) {
        uni.showToast({
          title: '请输入正确的手机号',
          icon: 'none'
        });
        return;
      }
      this.$api('index.get_coupon', { id: this.order_id, mobile: this.acceptMobile }).then(res => {
        if (res.code == 1) {
          uni.showToast({
            title: '您已领劵，快下载APP咨询律师吧',
            icon: 'none'
          });
        } else {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          });
        }
        setTimeout(() => {
          window.location.href = 'https://a.app.qq.com/o/simple.jsp?pkgname=com.lifakeji.lark.business.law';
        }, 2000);
      });
    }
  }
};
</script>

<style lang="scss">
.accept-box {
  width: 100%;
  height: 100%;
  background-color: #e11b3c;
  padding-bottom: 120rpx;
  width: 100%;
  .inv-top {
    width: 100%;
  }
  .inv-bot {
    display: block;
    margin: 60rpx auto;
    height: 60rpx;
  }
  .item-phone {
    color: #ffffff;
    font-size: 30rpx;
    margin-top: 40rpx;
    text-align: center;
    font-weight: bold;
    text-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.4);
  }
  .inv-bot-ipt-box {
    display: flex;
    margin: 0 auto;
    width: calc(100% - 160rpx);
    background-color: #ffffff;
    border-radius: 10rpx;
    align-items: center;
    input {
      flex: 1;
      font-size: 28rpx;
      padding: 10rpx;
    }
    .item-txt {
      padding: 15rpx 20rpx;
      border-radius: 10rpx;
      color: #ffffff;
      text-align: center;
      background: linear-gradient(to right, #9730E9, #5100B8);
    }
  }
}
.coupon-new{
  width: 400rpx;
  margin: 0 auto 30rpx;
  image{
    width: 100%;
    height: 100%;
  }
}
.top_200{
  //position: absolute;
  //overflow: hidden;
  //height: 380vh!important;
}
.anzhuoheight{
  //height:350vh!important;
}
</style>
